package com.ruoyi.web.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.UserAnswerscores;
import com.ruoyi.system.service.IUserAnswerscoresService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户答题成绩管理Controller
 * 
 * @author ruoyi
 * @date 2022-08-19
 */
@Controller
@RequestMapping("/system/answerscores")
public class UserAnswerscoresController extends BaseController
{
    private String prefix = "system/answerscores";

    @Autowired
    private IUserAnswerscoresService userAnswerscoresService;

    @RequiresPermissions("system:answerscores:view")
    @GetMapping()
    public String answerscores()
    {
        return prefix + "/answerscores";
    }

    /**
     * 查询用户答题成绩管理列表
     */
    @RequiresPermissions("system:answerscores:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UserAnswerscores userAnswerscores)
    {
        startPage();
        List<UserAnswerscores> list = userAnswerscoresService.selectUserAnswerscoresList(userAnswerscores);
        return getDataTable(list);
    }

    /**
     * 导出用户答题成绩管理列表
     */
    @RequiresPermissions("system:answerscores:export")
    @Log(title = "用户答题成绩管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UserAnswerscores userAnswerscores)
    {
        List<UserAnswerscores> list = userAnswerscoresService.selectUserAnswerscoresList(userAnswerscores);
        ExcelUtil<UserAnswerscores> util = new ExcelUtil<UserAnswerscores>(UserAnswerscores.class);
        return util.exportExcel(list, "用户答题成绩管理数据");
    }

    /**
     * 新增用户答题成绩管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户答题成绩管理
     */
    @RequiresPermissions("system:answerscores:add")
    @Log(title = "用户答题成绩管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(UserAnswerscores userAnswerscores)
    {
        return toAjax(userAnswerscoresService.insertUserAnswerscores(userAnswerscores));
    }

    /**
     * 修改用户答题成绩管理
     */
    @RequiresPermissions("system:answerscores:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        UserAnswerscores userAnswerscores = userAnswerscoresService.selectUserAnswerscoresById(id);
        mmap.put("userAnswerscores", userAnswerscores);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户答题成绩管理
     */
    @RequiresPermissions("system:answerscores:edit")
    @Log(title = "用户答题成绩管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(UserAnswerscores userAnswerscores)
    {
        return toAjax(userAnswerscoresService.updateUserAnswerscores(userAnswerscores));
    }

    /**
     * 删除用户答题成绩管理
     */
    @RequiresPermissions("system:answerscores:remove")
    @Log(title = "用户答题成绩管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(userAnswerscoresService.deleteUserAnswerscoresByIds(ids));
    }
}
